package net.bac.sbe.common.svn.helper;

import java.io.File;

import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;

public final class SBESVNClient {
	
	private SBESVNClient(){
		super();
	}
	
	private static SVNClientManager ourClientManager = SVNClientManager.newInstance();

	public static long checkout(SVNURL url, SVNRevision revision,
			File destPath) throws SVNException {

		SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
		/*
		 * sets externals not to be ignored during the checkout
		 */
		updateClient.setIgnoreExternals(false);
		/*
		 * returns the number of the revision at which the working copy is
		 */
		return updateClient.doCheckout(url, destPath, revision, revision, SVNDepth.INFINITY, true);
	}
	
	public static void commit(File filepath) throws SVNException {

		SVNCommitClient updateClient = ourClientManager.getCommitClient();
		/*
		 * sets externals not to be ignored during the checkout
		 */
		updateClient.setIgnoreExternals(false);
		/*
		 * returns the number of the revision at which the working copy is
		 */
		updateClient.doCommit( new File[] { filepath } , true , "Mensaje" , false , true );
	}
}
